﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;

namespace Silver.TaskbarFormDemo
{
    public partial class Form1 : Form
    {
        bool capture = false;
        int prevMouseX = 0;
        int prevMouseY = 0;

        public Form1()
        {
            InitializeComponent();
            this.TopMost = true;
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
           /* Image bg = Image.FromFile(@"..\..\..\img\bg.png");
            this.BackgroundImage = bg;
            this.BackgroundImageLayout = ImageLayout.Center;
            int width = bg.Width;
            int height = bg.Height;
            this.Width = width - 80;
            this.Height = height - 60;
            this.StartPosition = FormStartPosition.Manual;
            this.Top = Screen.PrimaryScreen.Bounds.Height - height;
            this.Left = Screen.PrimaryScreen.Bounds.Width - width;
            this.Click += new EventHandler(Form1_Click);
            this.MouseDown += new MouseEventHandler(Form1_MouseDown);
            this.MouseUp += new MouseEventHandler(Form1_MouseUp);
            this.MouseMove += new MouseEventHandler(Form1_MouseMove);*/

        }

        void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            if (capture)
            {
                this.Left += e.X - prevMouseX;
                this.Top += e.Y - prevMouseY;
            }
        }

        void Form1_MouseUp(object sender, MouseEventArgs e)
        {
            capture = false;
        }

        void Form1_MouseDown(object sender, MouseEventArgs e)
        {
            prevMouseX = e.X;
            prevMouseY = e.Y;
            capture = true;
        }

        void Form1_Click(object sender, EventArgs e)
        {
            MouseEventArgs arg = e as MouseEventArgs;
            if (arg.Button == System.Windows.Forms.MouseButtons.Right)
                contextMenuStrip1.Show(sender as Control, arg.Location);
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(@"http://www.kitco.cn/KitcoDynamicSite/RequestHandler?requestName=getFileContent&AttributeId=PreciousMetalsSpotPricesCNY
");
            HttpWebResponse myresponse = (HttpWebResponse)request.GetResponse();
            Stream mystream = myresponse.GetResponseStream();
            StreamReader sr = new StreamReader(mystream, System.Text.Encoding.GetEncoding("gb2312"));
            string html = sr.ReadToEnd();

            String pattern = "<(td)*?[^>]*>.*</td>";
            Regex reg = new Regex(pattern);

            foreach (Match match in reg.Matches(html))
            {
                if (match.Value.Contains("白银") == true)
                {

                    Match newmatch = match.NextMatch().NextMatch();
                     
                      this.textBox_date.Text = this.delete(newmatch.ToString());

                      this.textBox_buy.Text =this.delete( newmatch.NextMatch().ToString());
                     this.textBox_sell.Text = this .delete(newmatch.NextMatch().NextMatch().ToString());
                     
                  

                    
                }
               


            }
           // int c = Convert.ToInt32(count);

            
            

            sr.Close();

            //this.textBox1.Text = html;
            


        }

        public string  delete(string source)
        {
            String pattern1 = "<(td)*?[^>]*>";
            Regex reg = new Regex(pattern1);

            string result=reg.Replace(source, "");
            return result;
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }


    }
}
